package constant.milk.toilet.timer;

import constant.milk.toilet.R;
import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;

public class TimerService extends Service
{
	public void onCreate()
	{
		super.onCreate();
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId)
	{
		SharedPreferences p = getSharedPreferences("pref", Activity.MODE_PRIVATE);
		SharedPreferences.Editor e = p.edit();
		
		int hour = p.getInt(getString(R.string.prefHour), 0);
		int min = p.getInt(getString(R.string.prefMin), 0);
		int sec = p.getInt(getString(R.string.prefSec), 0);
		
		if (sec == 59)
		{
			sec = 0;
			
			if (min == 59)
			{
				hour = hour + 1;
				min = 0;
			} 
			else
			{
				min = min + 1;
			}
		} 
		else
		{
			sec = sec + 1;
		}
		
		e.putInt(getString(R.string.prefHour), hour);
		e.putInt(getString(R.string.prefMin), min);
		e.putInt(getString(R.string.prefSec), sec);
		e.commit();
		
		
		return START_NOT_STICKY;
	}
	
	@Override
	public void onDestroy()
	{
		super.onDestroy();
	}
	
	@Override
	public IBinder onBind(Intent intent)
	{
		return null;
	}
}
